<template>
	<view class="u-flex u-col-center u-row-between u-p-30 u-type-white-bg u-radius-10 u-m-tb-20" @click="navigatorTo('/pages/address/index?selectType=1')">
		<view v-if="address.id" class="u-m-r-30">
			<view class="u-font-22 u-content-color"><u-tag v-if="address.is_default" text="默认" type="success" size="mini" bg-color="#009476" mode="dark" class="u-m-r-20"></u-tag> {{address.province + ' ' + address.city + ' ' + address.county}}</view>
			<view class="u-m-tb-30 u-font-30 u-font-bold">{{address.province + address.city + address.county + address.address}}</view>
			<view class="u-font-22 u-content-color">{{address.username}} {{address.phone}}</view>
		</view>
		<view v-else>请选择地址</view>
		<u-icon name="arrow-right" size="28" color="#848484"></u-icon>
	</view>
</template>

<script>
	export default {
		
		data() {
			return {
				address: {}
			}
		},
		mounted(){
			this.getAddress()
			uni.$on('selectAddressId',this.selectAddressId)
		},
		destroyed(){
			uni.$off('selectAddressId',this.selectAddressId)
		},
		methods: {
			selectAddressId(id){
				this.$emit('changeAddress',id)
				this.getAddress(id)
			},
			// 获取地址信息
			getAddress(address_id) {
				let e = {};
				this.$u.api.findShopAddressList().then(res => {
					if (address_id) {
						e = res.data.filter(item => {
							if (address_id == item.id) {
								return item;
							}
						})[0];
					} else {
						e = res.data.filter(item => {
							if (item.is_default) {
								return item;
							}
						})[0] || {};
						this.$emit('changeAddress', Object.keys(e).length ? e.id : '')
					}
					this.address = {
						...e
					};
				});
			},
			navigatorTo(url){
				this.$u.route(url)
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>